package com.cgsd.heyu.ui.info;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cgsd.heyu.R;
import com.cgsd.heyu.common.AvatarManger;
import com.cgsd.heyu.common.UserModeConfig;
import com.cgsd.heyu.entity.AbonusEntity;
import com.cgsd.heyu.presenter.home.HomeContract;
import com.cgsd.heyu.presenter.home.HomePresenter;
import com.cgsd.heyu.ui.BaseActivity;

/**
 * @author xiaoxing
 * Description 代理中心
 * CreateData: 2021/1/7
 */
public class AbonusActivity extends BaseActivity<HomeContract.Presenter> implements HomeContract.AbonusView, View.OnClickListener {
    private ImageView ivAvatar;
    private TextView tvNickName;

    private TextView tvIntegral;
    private TextView tvIntegralContent;

    private TextView tvAbounsAddNumber1;
    private TextView tvAbounsProvinceNumber1;
    private LinearLayout tvAbounsCity1;
    private TextView tvAbounsCityNumber1;
    private LinearLayout tvAbounsProvince1;
    private TextView tvAbounsAreaNumber1;
    private TextView tvAbounsAddNumber2;
    private TextView tvAbounsProvinceNumber2;
    private LinearLayout tvAbounsCity2;
    private TextView tvAbounsCityNumber2;
    private LinearLayout tvAbounsProvince2;
    private TextView tvAbounsAreaNumber2;
    private TextView tvAbounsAddNumber3;
    private TextView tvAbounsProvinceNumber3;
    private LinearLayout tvAbounsCity3;
    private TextView tvAbounsCityNumber3;
    private LinearLayout tvAbounsProvince3;
    private TextView tvAbounsAreaNumber3;
    protected Context mContext;
    private String totalAmount = "0";


    public static void actionStart(Activity activity){
        Intent intent = new Intent(activity, AbonusActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_abouns;
    }

    @Override
    protected void initView() {
        new HomePresenter(this);
        ivAvatar = findViewById(R.id.iv_avatar);
        tvNickName = findViewById(R.id.tv_nickName);

        tvIntegral = findViewById(R.id.tv_integral);
        tvIntegralContent = findViewById(R.id.tv_integral_contenet);

        tvAbounsAddNumber1 = findViewById(R.id.tv_abouns_add_number1);
        tvAbounsProvinceNumber1 = findViewById(R.id.tv_abouns_province_number1);
        tvAbounsCity1 = findViewById(R.id.tv_abouns_city1);
        tvAbounsCityNumber1 = findViewById(R.id.tv_abouns_city_number1);
        tvAbounsProvince1 = findViewById(R.id.tv_abouns_province1);
        tvAbounsAreaNumber1 = findViewById(R.id.tv_abouns_area_number1);
        tvAbounsAddNumber2 = findViewById(R.id.tv_abouns_add_number2);
        tvAbounsProvinceNumber2 = findViewById(R.id.tv_abouns_province_number2);
        tvAbounsCity2 = findViewById(R.id.tv_abouns_city2);
        tvAbounsCityNumber2 = findViewById(R.id.tv_abouns_city_number2);
        tvAbounsProvince2 = findViewById(R.id.tv_abouns_province2);
        tvAbounsAreaNumber2 = findViewById(R.id.tv_abouns_area_number2);
        tvAbounsAddNumber3 = findViewById(R.id.tv_abouns_add_number3);
        tvAbounsProvince3 = findViewById(R.id.tv_abouns_province3);
        tvAbounsProvinceNumber3 = findViewById(R.id.tv_abouns_province_number3);
        tvAbounsCity3 = findViewById(R.id.tv_abouns_city3);
        tvAbounsCityNumber3 = findViewById(R.id.tv_abouns_city_number3);
        tvAbounsAreaNumber3 = findViewById(R.id.tv_abouns_area_number3);

        tvAbounsCity1.setVisibility(View.GONE);
        tvAbounsCity2.setVisibility(View.GONE);
        tvAbounsCity3.setVisibility(View.GONE);
        tvAbounsProvince1.setVisibility(View.GONE);
        tvAbounsProvince2.setVisibility(View.GONE);
        tvAbounsProvince3.setVisibility(View.GONE);


        findViewById(R.id.tv_abouns_add1).setOnClickListener(this);
        findViewById(R.id.tv_abouns_add2).setOnClickListener(this);
        findViewById(R.id.tv_abouns_add3).setOnClickListener(this);
        findViewById(R.id.tv_abonus_team).setOnClickListener(this);
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_abouns_add1://全部
                AbonusRecordActivity.actionStart(this, totalAmount, 0);
                break;
            case R.id.tv_abouns_add2://待结算
                AbonusRecordActivity.actionStart(this, totalAmount, 1);
                break;
            case R.id.tv_abouns_add3://已结算
                AbonusRecordActivity.actionStart(this, totalAmount, 2);
                break;
            case R.id.tv_abonus_team://已结算
                AbonusTeamActivity.actionStart(this);
                break;

            default:
        }
    }


    @Override
    protected void initData() {
        mPresenter.getAbonusData();
    }


    @Override
    public void setAbonusData(AbonusEntity entity) {
        AvatarManger.setAvatar(mContext, UserModeConfig.getInstance().headImgUrl, ivAvatar);
        tvNickName.setText(UserModeConfig.getInstance().nickName);
        if (entity != null){
            tvIntegral.setText(entity.thisTotalAmount);
            tvIntegralContent.setText(entity.thisTotalContent);
            totalAmount = entity.totalAmount;
            tvAbounsAddNumber1.setText(entity.totalAmount);
            tvAbounsProvinceNumber1.setText(entity.provinceTotalAmount);
            tvAbounsCityNumber1.setText(entity.cityTotalAmount);
            tvAbounsAreaNumber1.setText(entity.areaTotalAmount);

            tvAbounsAddNumber2.setText(entity.unsettledAmount);
            tvAbounsProvinceNumber2.setText(entity.provinceUnsettledAmount);
            tvAbounsCityNumber2.setText(entity.cityUnsettledAmount);
            tvAbounsAreaNumber2.setText(entity.areaUnsettledAmount);

            tvAbounsAddNumber3.setText(entity.settledAmount);
            tvAbounsProvinceNumber3.setText(entity.provinceSettledAmount);
            tvAbounsCityNumber3.setText(entity.citySettledAmount);
            tvAbounsAreaNumber3.setText(entity.areaSettledAmount);

            //abonutType
            if (entity.abonutType == 1){//省代理
                tvAbounsCity1.setVisibility(View.VISIBLE);
                tvAbounsCity2.setVisibility(View.VISIBLE);
                tvAbounsCity3.setVisibility(View.VISIBLE);
                tvAbounsProvince1.setVisibility(View.VISIBLE);
                tvAbounsProvince2.setVisibility(View.VISIBLE);
                tvAbounsProvince3.setVisibility(View.VISIBLE);
            }else if (entity.abonutType == 2){//市代理
                tvAbounsProvince1.setVisibility(View.VISIBLE);
                tvAbounsProvince2.setVisibility(View.VISIBLE);
                tvAbounsProvince3.setVisibility(View.VISIBLE);
            }



        }
    }

}
